]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
ci: Replace custom commit-log script with ci-fairy
authorFlorian Müllner <fmuellner@gnome.org>
Tue, 15 Dec 2020 16:57:12 +0000 (17:57 +0100)
committerFlorian Müllner <fmuellner@gnome.org>
Mon, 11 Jan 2021 13:01:44 +0000 (14:01 +0100)
ci-fairy now supports checking commit messages for required/disallowed
patterns. Use that to replace our custom commit-log script.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1544>

.gitlab-ci.yml
.gitlab-ci/check-commit-log.sh [deleted file]
.gitlab-ci/commit-rules.yml [new file with mode: 0644]

index 07fb97a88ce8705806598891bb2ea1a63d41363d..9cf82c416e9d95e1972960ed497dbc1320b2a6a1 100644 (file)
@@ -1,7 +1,7 @@
 include:
     - remote: 'https://gitlab.gnome.org/GNOME/citemplates/raw/master/flatpak/flatpak_ci_initiative.yml'
     - remote: 'https://gitlab.freedesktop.org/freedesktop/ci-templates/-/raw/7ea696055e322cc7aa4bcbe5422b56a198c4bdff/templates/fedora.yml'
-    - remote: "https://gitlab.freedesktop.org/freedesktop/ci-templates/-/raw/8445ff7af2a68795afb98f486251f2ef8f90621c/templates/ci-fairy.yml"
+    - remote: "https://gitlab.freedesktop.org/freedesktop/ci-templates/-/raw/6f86b8bcb0cd5168c32779c4fea9a893c4a0c046/templates/ci-fairy.yml"
 
 stages:
  - pre_review
@@ -80,7 +80,12 @@ check_commit_log:
     variables:
         GIT_DEPTH: "100"
     script:
-        - ./.gitlab-ci/check-commit-log.sh
+        - if [[ x"$CI_MERGE_REQUEST_TARGET_BRANCH_NAME" != "x" ]] ;
+          then
+            ci-fairy check-commits --junit-xml=commit-message-junit-report.xml ;
+          else
+            echo "Not a merge request" ;
+          fi
     <<: *pipeline_guard
     artifacts:
         expire_in: 1 week
diff --git a/.gitlab-ci/check-commit-log.sh b/.gitlab-ci/check-commit-log.sh
deleted file mode 100755 (executable)
index ac74b9b..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-#!/usr/bin/env bash
-
-if [ -z "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME" ]; then
-  echo This is not a merge request, skipping
-  exit 0
-fi
-
-git fetch $CI_MERGE_REQUEST_PROJECT_URL.git $CI_MERGE_REQUEST_TARGET_BRANCH_NAME
-
-branch_point=$(git merge-base HEAD FETCH_HEAD)
-
-commits=$(git log --format='format:%H' $branch_point..$CI_COMMIT_SHA)
-
-if [ -z "$commits" ]; then
-  echo Commit range empty
-  exit 1
-fi
-
-JUNIT_REPORT_TESTS_FILE=$(mktemp)
-
-function append_failed_test_case() {
-  test_name="$1"
-  commit="$2"
-  test_message="$3"
-  commit_short=${commit:0:8}
-
-  echo "<testcase name=\"$test_name: $commit_short\"><failure message=\"$commit_short: $test_message\"/></testcase>" >> $JUNIT_REPORT_TESTS_FILE
-  echo &>2 "Commit check failed: $commit_short: $test_message"
-}
-
-function append_passed_test_case() {
-  test_name="$1"
-  commit="$2"
-  commit_short=${commit:0:8}
-  echo "<testcase name=\"$test_name: $commit_short\"></testcase>" >> $JUNIT_REPORT_TESTS_FILE
-}
-
-function generate_junit_report() {
-  junit_report_file="$1"
-  num_tests=$(cat "$JUNIT_REPORT_TESTS_FILE" | wc -l)
-  num_failures=$(grep '<failure ' "$JUNIT_REPORT_TESTS_FILE" | wc -l )
-
-  echo Generating JUnit report \"$(pwd)/$junit_report_file\" with $num_tests tests and $num_failures failures.
-
-  cat > $junit_report_file << __EOF__
-<?xml version="1.0" encoding="utf-8"?>
-<testsuites tests="$num_tests" errors="0" failures="$num_failures">
-<testsuite name="commit-review" tests="$num_tests" errors="0" failures="$num_failures" skipped="0">
-$(< $JUNIT_REPORT_TESTS_FILE)
-</testsuite>
-</testsuites>
-__EOF__
-}
-
-function commit_message_has_mr_url() {
-  commit=$1
-  commit_message=$(git show -s --format='format:%b' $commit)
-  echo "$commit_message" | grep -qe "^$CI_MERGE_REQUEST_PROJECT_URL\/\(-\/\)\?merge_requests\/$CI_MERGE_REQUEST_IID$"
-  return $?
-}
-
-for commit in $commits; do
-  if commit_message_has_mr_url $commit; then
-    append_failed_test_case superfluous_url $commit \
-      "Commit message must not contain a link to its own merge request"
-  else
-    append_passed_test_case superfluous_url $commit
-  fi
-done
-
-generate_junit_report commit-message-junit-report.xml
-
-! grep -q '<failure' commit-message-junit-report.xml
-exit $?
diff --git a/.gitlab-ci/commit-rules.yml b/.gitlab-ci/commit-rules.yml
new file mode 100644 (file)
index 0000000..ef7d080
--- /dev/null
@@ -0,0 +1,4 @@
+patterns:
+  deny:
+    - regex: '^$CI_MERGE_REQUEST_PROJECT_URL/(-/)?merge_requests/$CI_MERGE_REQUEST_IID$'
+      message: Commit message must not contain a link to its own merge request